MV_CC_StartRecord

MV_CC_StartRecord

Start recording.

API Definition

int MV_CC_StartRecord(
  void                  *handle,
  MV_CC_RECORD_PARAM    *pstRecordParam
  );

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

pstRecordParam

[IN] Video parameters

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

The following sample code is for reference only.

#include <stdio.h>

#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"
bool g_bExit = false;
unsigned int g_nPayloadSize = 0;

// Wait for key input
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
static  unsigned int __stdcall WorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * (g_nPayloadSize));
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    MV_CC_INPUT_FRAME_INFO stInputFrameInfo = {0};
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)
        {
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n" 
            stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
            stInputFrameInfo.pData = pData;
            stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
            nRet = MV_CC_InputOneFrame(pUser, &stInputFrameInfo);
            if (MV_OK != nRet)
            {
                printf("Input one frame fail! nRet [0x%x]\n", nRet);
            }
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
        {
            break;
        }
    }
    free(pData);
    return 0;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do 
    {
        // Enumerate device
          MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return 0;
        }

        // Select device and create handle
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Open device
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Detect the optimal network packet size (It works only for GigE camera)
        if (stDeviceList.pDeviceInfo[0]->nTLayerType == MV_GIGE_DEVICE)
        {
            int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
            if (nPacketSize > 0)
            {
                nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
                if(nRet != MV_OK)
                {
                    printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
                }
            }
            else
            {
                printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);
            }
        }

        // Set triggering mode to Off
        nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0);
        if (MV_OK != nRet)
        {
            printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Get packet size
          MVCC_INTVALUE stParam;
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
            break;
        }
        g_nPayloadSize = stParam.nCurValue;
        MV_CC_RECORD_PARAM stRecordPar = {0};
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "Width", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nHeight = stParam.nCurValue;
        MVCC_ENUMVALUE stEnumValue;
        nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &stEnumValue);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.enPixelType = MvGvspPixelType(stEnumValue.nCurValue);
        MVCC_FLOATVALUE stFloatValue;
        nRet = MV_CC_GetFloatValue(handle, "AcquisitionFrameRate", &stFloatValue);
        if (MV_OK != nRet)
        {
            printf("Get Float value fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Frame rate (1/16-120)fps
        stRecordPar.fFrameRate = stFloatValue.fCurValue;

        // Bit rate kbps(128kbps-16Mbps)
        stRecordPar.nBitRate = 1000;

        // Video format (supports only AVI format)
        stRecordPar.enRecordFmtType = MV_FormatType_AVI;
        stRecordPar.strFilePath= "./Recording.avi";
        nRet = MV_CC_StartRecord(handle,&stRecordPar);
        if (MV_OK != nRet)
        {
            printf("Start Record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Start acquisition
          nRet = MV_CC_StartGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        unsigned int nThreadID = 0;
        void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID );
        if (NULL == hThreadHandle)
        {
            break;
        }
        printf("Press a key to stop grabbing.\n");
        WaitForKeyPress();
        g_bExit = true;
        Sleep(1000);

        // Stop acquisition
          nRet = MV_CC_StopGrabbing(handle);
        if (MV_OK != nRet)
        {
             printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
             break;
        }
        nRet = MV_CC_StopRecord(handle);
        if (MV_OK != nRet)
        {
            printf("Stop record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Shut device
          nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Destroy handle and release resource
          nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    }while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

MV_CC_StartRecord

Start recording.

API Definition

int MV_CC_StartRecord(
  void                  *handle,
  MV_CC_RECORD_PARAM    *pstRecordParam
  );

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

pstRecordParam

[IN] Video parameters

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

The following sample code is for reference only.

#include <stdio.h>

#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"
bool g_bExit = false;
unsigned int g_nPayloadSize = 0;

// Wait for key input
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
static  unsigned int __stdcall WorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * (g_nPayloadSize));
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    MV_CC_INPUT_FRAME_INFO stInputFrameInfo = {0};
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)
        {
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n" 
            stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
            stInputFrameInfo.pData = pData;
            stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
            nRet = MV_CC_InputOneFrame(pUser, &stInputFrameInfo);
            if (MV_OK != nRet)
            {
                printf("Input one frame fail! nRet [0x%x]\n", nRet);
            }
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
        {
            break;
        }
    }
    free(pData);
    return 0;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do 
    {
        // Enumerate device
          MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return 0;
        }

        // Select device and create handle
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Open device
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Detect the optimal network packet size (It works only for GigE camera)
        if (stDeviceList.pDeviceInfo[0]->nTLayerType == MV_GIGE_DEVICE)
        {
            int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
            if (nPacketSize > 0)
            {
                nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
                if(nRet != MV_OK)
                {
                    printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
                }
            }
            else
            {
                printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);
            }
        }

        // Set triggering mode to Off
        nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0);
        if (MV_OK != nRet)
        {
            printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Get packet size
          MVCC_INTVALUE stParam;
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
            break;
        }
        g_nPayloadSize = stParam.nCurValue;
        MV_CC_RECORD_PARAM stRecordPar = {0};
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "Width", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nHeight = stParam.nCurValue;
        MVCC_ENUMVALUE stEnumValue;
        nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &stEnumValue);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.enPixelType = MvGvspPixelType(stEnumValue.nCurValue);
        MVCC_FLOATVALUE stFloatValue;
        nRet = MV_CC_GetFloatValue(handle, "AcquisitionFrameRate", &stFloatValue);
        if (MV_OK != nRet)
        {
            printf("Get Float value fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Frame rate (1/16-120)fps
        stRecordPar.fFrameRate = stFloatValue.fCurValue;

        // Bit rate kbps(128kbps-16Mbps)
        stRecordPar.nBitRate = 1000;

        // Video format (supports only AVI format)
        stRecordPar.enRecordFmtType = MV_FormatType_AVI;
        stRecordPar.strFilePath= "./Recording.avi";
        nRet = MV_CC_StartRecord(handle,&stRecordPar);
        if (MV_OK != nRet)
        {
            printf("Start Record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Start acquisition
          nRet = MV_CC_StartGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        unsigned int nThreadID = 0;
        void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID );
        if (NULL == hThreadHandle)
        {
            break;
        }
        printf("Press a key to stop grabbing.\n");
        WaitForKeyPress();
        g_bExit = true;
        Sleep(1000);

        // Stop acquisition
          nRet = MV_CC_StopGrabbing(handle);
        if (MV_OK != nRet)
        {
             printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
             break;
        }
        nRet = MV_CC_StopRecord(handle);
        if (MV_OK != nRet)
        {
            printf("Stop record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Shut device
          nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }

        // Destroy handle and release resource
          nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    }while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}